package com.sfh.cpc.note;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sfh.cpc.R;
import com.sfh.cpc.com.BaseAppContent;
import com.sfh.cpc.com.ImageLoaderEngine;
import com.sfh.cpc.com.entity.EMessage;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.cpc.com.ui.UtilTime;
import com.sfh.cpc.com.widget.VIPAgeUserView;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/29
 */
public class MessageAdapter extends BaseQuickAdapter<EMessage,BaseViewHolder> {
    public MessageAdapter() {
        super(R.layout.note_msg_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, EMessage item) {
        EUser user = item.getUser();
        if (user != null) {
            helper.setText(R.id.tvName, user.getUserName());
            helper.setImageResource(R.id.ivSex, TextUtils.equals("1", user.getUserSex()) ? com.sfh.cpc.com.R.drawable.tag_male : com.sfh.cpc.com.R.drawable.tag_female);
            VIPAgeUserView vip =    helper.getView(R.id.tvAddress);
            vip.showVIP(user);

            ImageView ivHead = helper.getView(R.id.ivHeadr);

            if (TextUtils.isEmpty(user.getUserUrl())) {
                ivHead.setImageResource(com.sfh.cpc.com.R.drawable.wait_head_second);
            } else {
                new ImageLoaderEngine(ivHead, BaseAppContent.getImageUrl(user.getUserUrl())).resizeDimen(com.sfh.cpc.com.R.dimen.px_100, com.sfh.cpc.com.R.dimen.px_100).placeholder(com.sfh.cpc.com.R.drawable.wait_head_second).error(com.sfh.cpc.com.R.drawable.wait_head_second).centerCrop().into(ivHead);
            }
        }
        helper.addOnClickListener(R.id.ivHeadr);
        helper.setText(R.id.tvTime, UtilTime.getFriendlyTime(item.getMsgCreateTime()));
        helper.setText(R.id.tvContent, item.getMsgContent());
    }



}
